/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.exam;

import java.io.*;
import java.util.UUID;

/**
 * <p>Project: javase - Ex1
 * <p>Powered by webrx On 2021-12-14 14:34:49
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex1 {
    public static void main(String[] args) {
        //建立文件
        try (var fos = new FileOutputStream("user.txt")) {
            for (int i = 0; i < 110; i++) {
                var u = UUID.randomUUID().toString().toLowerCase().concat(".jpg\r\n");
                fos.write(u.getBytes());
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        //删除文件 linux rm
        //var f = new File("user.txt");
        //if (f.exists()) f.deleteOnExit();

        //文件更名，也可实现文件的移动相当于linux mv
        //var f = new File("user.txt");
        //f.renameTo(new File("c:/x.txt"));
        //f.renameTo(new File("userabc.txt"));

        //文件复制
        try (var b = new FileOutputStream("c:/abcu.txt"); var a = new FileInputStream("userabc.txt")) {
            //b.write(a.readAllBytes());
            a.transferTo(b);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
